<?php
function getNavegacao($page = null) {
	$pages = array (
			"index" => "index.php",
			"post" => "Noticia",
			"cadastro" => "Cadastro",
			"adicionar" => "Nova Notícia",
			"postagens" => "Minhas Notícias",
			"senha" => 'Esquece Senha',
			"contato" => 'Contato',
			"usuario" => 'Meus Dados',
			"alterar" => 'Editar Notícia'
			);

			$html = '<ol class="breadcrumb">';
			if (is_null ( $page )) {
				$html .= '<li class="active"><a href="' . $pages ['index'] . '">Inicio</a></li>';
			} else {
				if (key_exists($page, $pages)) {
					$html .= '<li><a href="' . $pages ['index'] . '">Inicio</a></li>
				<li class="active"><a href="index.php?pag=' . $page . '">' . $pages[$page] . '</a></li>';
				}
			}
			$html .= '</ol>';
			return $html;
}

function checarUsuario($nivelTest = null){

	if(isset($_SESSION['user'])){

		if((!is_null($nivelTest)) && ($_SESSION['user_nivel'] > $nivelTest)){

			return false;

		}

		return true;

	}else{
		return false;
	}
}

function dataBancoByPt($data){
	$dataArray = explode('-', $data);
	$new_data = implode('/', array_reverse($dataArray));
	return $new_data;
}


function dataPtByBanco($data){
	$dataArray = explode('/', $data);
	$new_data = implode('-', array_reverse($dataArray));
	return $new_data;
}

function exipararSessao(){
	$temposessao = "1500";
	if ($_SESSION["sessiontime"]) {
		if ($_SESSION["sessiontime"] < (time() - $temposessao)) {
			$_SESSION['msg_info'] = "Seu tempo Expirou!";
			
			unset($_SESSION['user']);
			unset($_SESSION['user_nivel']);
			unset($_SESSION['user_nome']);
			unset($_SESSION["sessiontime"]);
			
			header('location: index.php');
		}
	}
}
function email($dest,$assunto,$msg){
	$headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";
        $headers .= "From: Blog php <adm@blogphp.com.br>\r\n";
        mail($dest, $assunto, $texto, $msg);
}